package org.jeecg.modules.flow.sys.common;

import lombok.Data;
import org.apache.commons.lang.StringUtils;
import org.jeecg.modules.flow.sys.base.CustomBeanRunInterface;
import org.jeecg.modules.flow.sys.entity.dto.BaseFlowDto;
import org.jeecg.modules.flow.sys.service.WorkFlowService;
import org.jeecg.modules.flow.sys.util.SpringContextUtil;

/*
 * 项目名称:    wms-server-jeecg
 * 接口描述:    //
 * 创建人员:    zhaojun
 * 创建时间:    2023-09-20
 */
@Data
public abstract class BaseCustomBeanRun<T> implements CustomBeanRunInterface<T> {

    private BaseFlowDto baseFlowDto;

    @Override
    public void run(T data) {
        baseFlowDto = (BaseFlowDto)data;
        actureRun();
        String infoId = baseFlowDto.getInfoId();
        if(StringUtils.isNotBlank(infoId)){
            // 保存业务流程记录信息
            WorkFlowService workFlowService = (WorkFlowService) SpringContextUtil.getBean("workFlowServiceImpl");
            baseFlowDto.setInfoId(infoId);
            workFlowService.createFlowRecord(baseFlowDto);
        }
        resultConvert(baseFlowDto,data);
    }

    /**
     * 真实的业务执行
     * @return 如果前置中存在保存业务操作，就返回业务id，info_id；
     */
   public abstract void actureRun();
}
